const trim = require('trim')
const execSync = require('child_process').execSync;
const fs = require('fs')
const path = require('path')
const glob = require('glob')

module.exports = {
  getRevision(useLast = false){
    const commitHash = execSync('git rev-parse --short ' + (useLast ? 'HEAD^1' : 'HEAD')).toString(
      'ascii'
    )
    return commitHash.replace(/^\s+|\s+$/g, '');
  },
  getVersion(){
    const version = fs.readFileSync('../version.txt', 'utf-8')
    return trim(version)
  },
  getAllResourceImages(){
    return glob
      .sync('res/**/*.@(png|svg|jpg)', { cwd: '..' })
      .map(f => {
        return f.replace(/^res\//gi, "");
      })
      .filter(f => {
        if(f.indexOf('ui') >= 0){
          return f.indexOf('noinline') >= 0;
        }
        return true;
      })
  },

  // cachebust(url, commitHash){
  //   return "/v/" + commitHash + '/' + url;
  // }
}